package com.haoshuang.zhouzhoubang

import android.app.Application
import android.graphics.Color
import android.location.Address
import android.view.Gravity
import android.view.WindowManager
import cn.jiguang.api.utils.JCollectionAuth
import cn.jpush.android.api.JPushInterface
import cn.jzvd.JZUtils.getWindow
import com.blankj.utilcode.util.ToastUtils
import com.haoshuang.zhouzhoubang.model.bean.SystemConfigBean
import com.haoshuang.zhouzhoubang.model.http.HttpConfigImpl
import com.lnkj.jialubao.utils.AccountUtils
import com.mufeng.libs.MFLibs
import com.mufeng.libs.config.ResConfig
import com.mufeng.libs.net.RxHttpManager
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout

class MyApp : Application() {
    companion object {
        lateinit var instance: MyApp

        // 当前定位的经纬度
        var lat = ""
        var lng = ""

        // 当前定位的地址信息
        var address: Address? = null

        // 系统配置信息
        var systemConfig: SystemConfigBean? = null
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
        MFLibs.init(
            this,
            isDebug = true,
            defaultLogTag = "周周帮",
            httpConfig = HttpConfigImpl(),
            resConfig = object : ResConfig {
                override fun initRefresh() {
                    //设置全局的Header构建器
                    SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
                        ClassicsHeader(context)
                    }
                    //设置全局的Footer构建器
                    SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout ->
                        ClassicsFooter(context).setDrawableSize(20f)
                    }
                }
            },
        )
        RxHttpManager.init(this)


    }

    fun initJpush(){
        JPushInterface.setDebugMode(true)
        // 初始化代码前增加setAuth调用
        val isPrivacyReady = AccountUtils.isAgreementDialog
        if (!isPrivacyReady){
            JCollectionAuth.setAuth(applicationContext, false) // 后续初始化过程将被拦截
        }
        JPushInterface.init(applicationContext)
        // 隐私政策授权获取成功后调用
        JCollectionAuth.setAuth(applicationContext, true) //如初始化被拦截过，将重试初始化过程
    }
}